package com.ycsj.goldmedalnewconcept.teacher.activity;


import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.ycsj.common.base.BaseActivity;
import com.ycsj.common.base.BaseApplication;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.common.HttpAddress;
import com.ycsj.goldmedalnewconcept.common.http.HttpCallBack;
import com.ycsj.goldmedalnewconcept.common.http.HttpUtils;
import com.ycsj.goldmedalnewconcept.common.util.AccountUtils;
import com.ycsj.goldmedalnewconcept.teacher.adapter.StGvAdapter;
import com.ycsj.goldmedalnewconcept.teacher.bean.StStateInfo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 布置练习的学生名单
 * Created by Administrator on 2019/5/8 0008.
 */

public class TeacherLookStudentListActivity extends BaseActivity {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.gv)
    GridView gv;
    @BindView(R.id.rl_loading)
    RelativeLayout rlLoading;

    //班级和练习ID
    private String classnum, workid;

    /**
     * 跳转到当前界面的方法
     *
     * @param context
     * @param classnum
     */
    public static void goActivity(Context context, String classnum, String workid) {
        Intent it = new Intent(context, TeacherLookStudentListActivity.class);
        it.putExtra("classnum", classnum);
        it.putExtra("workid", workid);
        context.startActivity(it);
    }


    @Override
    protected int getContentLayout() {
        return R.layout.teacher_activity_look_stlist;
    }

    @Override
    protected void init() {

        initStateBar();

        //初始化标题
        initTitle();

        //获取数据
        initIntent();

        //请求数据
        http();
    }


    /**
     * 初始化标题
     */
    private void initTitle() {
        tvTitle.setText("接收练习的学生");
    }


    /**
     * 获取数据
     */
    private void initIntent() {
        classnum = getIntent().getStringExtra("classnum");
        workid = getIntent().getStringExtra("workid");
    }


    /**
     * 请求数据
     */
    private void http() {
        Map<String, String> map = new HashMap<>();
        map.put("type", "3");
        map.put("acc", AccountUtils.getAccount(this));
        map.put("classnum", classnum);
        map.put("workid", workid);
        map.put("role", AccountUtils.getRole(this));
        map.put("platform", "2");

        HttpUtils.post(HttpAddress.STLIST, map, this, new HttpCallBack<StStateInfo>() {
            @Override
            public void onSuccess(StStateInfo info) {
                rlLoading.setVisibility(View.GONE);
                if ("200".equals(info.getState())) {
                    //返回成功
                    List<StStateInfo.DataBean> oldDatas = info.getData();

                    StGvAdapter adapter = new StGvAdapter(TeacherLookStudentListActivity.this, oldDatas,
                            R.layout.teacher_item_st_list);
                    gv.setAdapter(adapter);

                } else {
                    ToastUtils.showShort(BaseApplication.STATEERROE + info.getState());
                }
            }

            @Override
            public void onError(String e) {
                rlLoading.setVisibility(View.GONE);
                ToastUtils.showShort(BaseApplication.ERROR);
            }
        });
    }


    /**
     * 点击事件
     *
     * @param view
     */
    @OnClick({R.id.iv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }
}
